#!/usr/bin/python
from pylab import *

# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib
from matplotlib.collections import PatchCollection
# import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.lines as mlines

# font = "sans-serif"
fig = figure(figsize=(5,5))
# ax = fig.add_axes([0,0,1,1])  # the ticks not displayed
# ax = fig.add_axes([0.1,0.1,0.8,0.8])
ax = fig.add_subplot(111)


x = arange(0,1,0.01)
plot(x,sin(2*pi*x))


# # create 3x3 grid to plot the artists
# # pos = np.mgrid[0.2:0.8:3j, 0.2:0.8:3j].reshape(2, -1)

patches = []

# add a circle
# art = mpatches.Circle(pos[:,0], 0.1,ec="none")
art = mpatches.Circle((0.5,0.5), 0.1,ec="none")
patches.append(art)
# ax.text(0.5, 0.5-0.15, "Circle", ha="center", family=font, size=14)

art = mpatches.Rectangle((0.5,0.5), 0.5, 0.2, ec='none')
# art = mpatches.Rectangle((0.5,0.5), 0.5, 0.2, fc='r', ec='none')
patches.append(art)

art = mpatches.Arrow(0,0,0.3,0.3,width=0.2)
patches.append(art)

# lines (not append to patches, added to ax)
line = mlines.Line2D([0,0.2],[0.3,0.4], lw=4, color='r', alpha=0.4) # draw a line (0,0.3) - (0.2,0.4)
lineX = linspace(0,2,5)
lineY = [0,0,1,0,0]
line = mlines.Line2D(lineX, lineY, lw=4, c='b', alpha=0.4)

setp(line, color='g')           # set the properties of 'line'


# colors = 100*np.random.rand(len(patches))
collection = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)
# collection.set_array(np.array(colors))
ax.add_collection(collection)


ax.add_line(line)               # add lines
xlim(0,2)                       # must set the xlim/ylim manually
# ax.set_xticks([])
# ax.set_yticks([])
ax.set_xticks([-1, -0.5, 0, 0.5, 1], ['$-\pi$', '$-\pi/2$', '$0$', '$+\pi/2$', '$+\pi$'])


savefig("tmp.png", dpi=72)
show()


